Click here to return to the VHDL Reference Guide. (last edit: 24. september 2012)

Aggregate

A way to write a value for any array or record.

Syntax

  aggregate->
    '('element-association { ',' element-association } ')'
  element-association ->
    [ choices '=>' ] expression
  choices -> choice { | choice } 
  choice -> simple-expression | discrete-range | element-simple-name | others
          

Placement

 PACKAGE Pack IS
   ... 
 END PACKAGE Pack;
 PACKAGE BODY Pack IS
   ... 
 END PACKAGE BODY Pack;
 Blk:BLOCK 
   ... 
 BEGIN 
   ... 
 END BLOCK Blk;
 ENTITY Ent IS
   ... 
 BEGIN 
   ... 
 END ENTITY Ent;
 ARCHITECTURE Arc OF Ent IS
   ... 
 BEGIN 
   ... 
 END ARCHITECTURE Arc;
 CONFIGURATION Conf OF Ent IS
   ... 
 END CONFIGURATION Conf;
 Proc:PROCESS(...) 
   ... 
 BEGIN 
   ... 
 END PROCESS Proc;
 PROCEDURE P(...) IS
   ... 
 BEGIN 
   ... 
 END PROCEDURE P;
 FUNCTION F(...) RETURN Tp IS
   ... 
 BEGIN
   ... 
 END FUNCTION F;

Rules

  • An aggregate must give a value for every element of the array or record.
  • The two forms of syntax (ordered list or explicitly named choices) can be mixed, but the ordered values must come before the named choices.
  • Aggregates are used to assign values to arrays and records. Both types and objects can get values using aggregates.
  • It is possible to use named association (for example "alarmTime" above) or positional association (for example "currentTime" above). Named association is preferable since then the order of the parameters does not impact the assignment.
  • OTHERS is used to assign values to the elements not already assigned. OTHERS must be placed as the last association in the aggregate.
  • For records, but not for arrays, it is possible (but not recommendable) to mix named and positional association. The only rule is that the positional associations must be placed before the named.

Things to remember

Aggregates frequently need to be qualified to disambiguate their type (see example below).

Synthesis

Many synthesis tools do not allow aggregates as targets of assignments.

Tips

The aggregate (others => Expression) is a very useful way of setting all the elements of an array to the same value; you do not even have to know how big the array is! For example, to set the value of a parameter of an unconstrained array type.

Example

  ('0', '1', '0', '1')
  (1, 2, 3, 4, 5)
  (1 => A, 2 => B, 3 => C)
  (1, 2, 3, others => 4)
  (others => 'Z')
  (A, B, C) := D;                   -- Aggregate as the target of an assignment
  T'(others => '0')                 -- Qualified expression
  (others => T'(others => '0'))

  TYPE Clock IS RECORD
    Hour : INTEGER RANGE 0 TO 23;
    Min  : INTEGER RANGE 0 TO 59;
    Sec  : INTEGER RANGE 0 TO 59;
  END RECORD Clock;
  
  TYPE Matrix IS ARRAY (0 TO 1, 0 TO 1) OF BIT;
  SUBTYPE MyArray IS BIT_VECTOR(2 TO 5);
  
  CONSTANT allZero : MyArray := (OTHERS => '0');
    ...
  SIGNAL currentTime, alarmTime : Clock;
  ... 
  VARIABLE m1, m2 : Matrix;
  VARIABLE v1, v2 : MyArray;
  ... 
  currentTime <= (10,15,5);
  
  alarmTime <= (Hour => 10, Min => 15, Sec => 5);
  m1 := (('0','1'),(OTHERS => '0')); --"01","00"
  m2 :=(OTHERS => (OTHERS => '1')); --"11","11"
  v1 := ('0', '1', '1', '1'); --"0111"
  v2 := (3 => '0', OTHERS => '1'); --"1011"
  (v1,v2) := ("0000","1111"); --v1 = "0000", v2 = "1111"
  
  --For a BIT_VECTOR this assignment is easier to write:
  v2 := "1011";
          

See Also

Array, Record, Expression, Range